<?php

require_once('php/lib/mvc/view.php');

/**
 * Yapter view for files.
 *
 * @author Pascal de Vink
 */
class YapterView extends View {
	
	/**
	 * Yapter instance.
	 *
	 * @var Yapter
	 * @access public
	 */
	var $yapter;
	
	/**
	 * Constructs new instance.
	 *
	 * @param string $url URL for file
	 * @access public
	 */
	function __construct($url) {
		parent::__construct();
		require_once('php/yapter/yapter_improved.php');
	
		$this->yapter =& new Yapter($url);
	
		
	}
	
	/**
	 * Sets variable for view
	 *
	 * @param string $var Name of variable.
	 * @param mixed $value Value of variable.
	 * @access public
	 */
	function set($var, $value) {
		$this->yapter->set($var, $value);
	}
	
		
	
	/**
	 * Sets variable by reference for view
	 *
	 * @param string $var Name of variable.
	 * @param mixed $value Value of variable.
	 * @access public
	 */
	function setByRef($var, &$value) {
		$this->yapter->setByRef($var, $value);
	}
	
	/**
	 * Parses block with given name.
	 *
	 * @param string block Name of block (defaults to whole file).
	 * @access public
	 */
	function parse($block) {
		$this->yapter->parse($block);
	}
	 
	/**
	 * Replaces contents of block with other block.
	 *
	 * @param string $block Name of block to be replaced.
	 * @param mixed $other_block Name of block with new content.
	 * @access public
	 */
	function replace($block, $other_block) {
		$this->yapter->replace($block, $other_block);
	}
	 
	/**
	 * Hides contents of block
	 *
	 * @param string $block Name of block to be hidden.
	 * @access public
	 */
	function hide($block) {
		$this->yapter->hide($block);
	}
	
	/**
	 * Resets parse state of block
	 *
	 * @param string $block Name of block to be reset.
	 * @access public
	 */
	function clear($block) {
		$this->yapter->clear($block);
	}
	
	/**
	 * @see View::render()
	 */
	function render() {
		$this->yapter->parse();
		$this->yapter->spit();
	}
	
	/**
	 * Indicates that missing variables should be treated as empty.
	 */
	function ignoreMissingVariables() {
		$this->yapter->setParseMode(true);
		$this->yapter->setWarningLevel(0);
	}
	
	function getContents() {
		return $this->yapter->spit();
	}
	
	
	function renderLanguage() {
		$lines = array();
		$lines = $this->yapter->missing_list;
		print_r($lines);
		
 	}
}
?>